﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LuaInterface;
using System.IO;

namespace RPGLUA
{
    class NPC
    {
        private Lua scriptPower;
        private string scriptName;
        private string name;

        public string interactKey;
        public NPC(string name, Lua lua)
        {
            this.name = name;
            this.interactKey = name[0].ToString();
            scriptName = name + ".lua";
            scriptPower = lua;
            scriptPower.DoFile(Directory.GetCurrentDirectory() + "\\" + scriptName);
        }

        public string Name
        {
            get
            {
                return (string)scriptPower[name + ".name"];
            }
        }

        public string Description
        {
            get
            {
                return (string)scriptPower[name + ".description"];
            }
        }

        public void Interact()
        {
            string answer = "";
            while (answer != "x")
            {
                Console.WriteLine("You are interacting with " + Name);
                Console.WriteLine("\tx to exit");
                Console.WriteLine("\tt to talk");
                Console.WriteLine("\tl to look");

                Console.Write(">");
                answer = Console.ReadLine();

                if (answer == "l")
                {
                    Console.WriteLine(this.Description);
                }
                else if (answer == "t")
                {
                    this.OnTalk();
                }
            }
        }

        public void OnTalk()
        {
            scriptPower.DoString("knight:OnTalk()");
        }

        public void Say(string say)
        {
            Console.WriteLine(Name + " says \"" + say + "\"");
        }

    }
}
